﻿using AIDotNet.Document.Contract;
using AIDotNet.Document.Contract.Models;
using Microsoft.AspNetCore.Components;

namespace AIDotNet.Document.Rcl.Pages;

public partial class MyFolder
{
    private string? CurrentFolderId { get; set; }

    /// <summary>
    /// 搜索关键字
    /// </summary>
    private string SearchKey { get; set; }

    /// <summary>
    /// 文件夹id
    /// </summary>
    [Parameter]
    [SupplyParameterFromQuery(Name = "folderId")]
    public string? FolderId { get; set; }

    public FolderItemDto FolderItemDto { get; set; } = new();

    private List<FolderItemDto> Folders { get; set; } = new();

    protected override async Task OnInitializedAsync()
    {
        Folders = await FolderService.GetTreeFolderAsync();

        if (FolderId != null)
        {
            if (FolderId == DocumentConstant.MyResources)
            {
                FolderItemDto = new FolderItemDto
                {
                    Id = DocumentConstant.MyResources,
                    Name = "我的资源",
                    IsFolder = true,
                    ParentId = null,
                    CreatedTime = DateTime.Now
                };
                return;
            }

            FolderItemDto = Folders.First(x => x.Id == FolderId);
        }
    }


    public void SelectFolder(string folderId)
    {
        FolderId = folderId;
    }

    public string GetClass(string folderId)
    {
        return folderId == FolderId ? "folder-item folder-item-selected" : "folder-item";
    }
}